package com.rran.study.designpattern.behavioral.memento;

import java.util.ArrayList;
import java.util.List;

/**
 * @author yy
 * @Type Caretaker.java
 * @Desc 存档管理器
 * @date 2020/7/24 12:59
 */
public class Caretaker implements  CaretakerAction{

    private List<Memento> mementos = new ArrayList<>();

    @Override
    public void addMemento(Memento memento){
        mementos.add(memento);
        System.out.println("存档成功");
    }

    @Override
    public Memento getMemento(String index){
        System.out.println("玩家读档中");
        for(Memento m : mementos){
            if (m.getIndex().equals(index)){
                return m;
            }
        }
        return null;
    }

}
